<?php

	class NewsCategory extends CI_Model
	{
		public function __construct()
		{
			parent::__construct();
		}

		function getCategory($id = false)
		{
			$query = $this->db->get_where('new_categories',array('id'=>$id));
			return $query->row_array();
		}

		function getAll($limit = false)
		{
			$query = $this->db->get('new_categories');
			if($limit)
			{
				$query = $this->db->get('new_categories',$limit,0);
			}
			return $query->result_array();
		}

		function getNewsOfCategory($id = false,$page = false)
		{
			$this->db->select('*');
			$this->db->from('news');
			$this->db->where('category_id',$id);

			if($page)
			{
				$this->db->limit(10,$page);
			}			
			else
			{
				$this->db->limit(10,0);
			}

			$query = $this->db->get();
			return $query->result_array();
		}

		function addNewCategory($data)
		{
			return $this->db->insert('new_categories',$data);
		}
	}